﻿namespace ClassyBlog.DataAccess.Specs.Unit
{
    using System;
    using System.Collections.Generic;
    using System.Dynamic;
    using System.Linq.Expressions;

    using DomainObjects;
    using Infrastructure;

    public class Article : IArticle
    {
        private readonly IDictionary<string, object> dynamicProperties =
            new Dictionary<string, object>();

        public Guid Id { get; set; }

        public string Title { get; set; }

        public string Slug { get; set; }

        public string Body { get; set; }

        public string FormattedBody { get; set; }

        public string Type { get; set; }

        public DateTime PublishedAt { get; set; }

        public string MetaKeywords { get; set; }

        public string MetaDescription { get; set; }

        public string Author { get; set; }

        public bool AllowComments { get; set; }

        public IEnumerable<string> DynamicPropertyNames
        {
            get { return dynamicProperties.Keys; }
        }

        public DynamicMetaObject GetMetaObject(Expression parameter)
        {
            return new DynamicPropertiesMetaObject(parameter, this);
        }

        public object GetDynamicProperty(string name)
        {
            object value;

            return dynamicProperties.TryGetValue(name, out value) ?
                   value :
                   null;
        }

        public void SetDynamicProperty(string name, object value)
        {
            dynamicProperties[name] = value;
        }
    }
}